package com.yc.demo.d0304Operation;

import com.google.gson.Gson;
import com.yc.demo.d0304.OnlineListener;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Map;

@WebServlet(name = "d0304OnlineServlet", value = "/d0304OnlineServlet")
public class d0304OnlineServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //获取当前在线人数
        final Map<String, Date> onlineUsers = OnlineListener.onlineUsers;
        final String json = new Gson().toJson(onlineUsers);
        response.getWriter().println(json);


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
